package com.ler.yrmall.order.controller;

import com.ler.yrmall.basic.Result;
import com.ler.yrmall.order.entity.OrderItemEntity;
import com.ler.yrmall.order.service.OrderItemService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 订单项信息
 *
 * @author Leron
 */
@RestController
@RequestMapping("/order-item")
public class OrderItemController {

    @Resource
    private OrderItemService orderItemService;

    /**
     * 信息
     */
    @RequestMapping("/getById/{id}")
    public Result<?> info(@PathVariable("id") Long id) {
        OrderItemEntity orderItem = orderItemService.getById(id);
        return Result.ok(orderItem);
    }

    @RequestMapping("/listByOrderId/{orderId}")
    public Result<?> listByOrderId(@PathVariable Long orderId) {
        return Result.ok(orderItemService.listByOrderId(orderId));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@RequestBody OrderItemEntity orderItem) {
        orderItemService.save(orderItem);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result<?> update(@RequestBody OrderItemEntity orderItem) {
        orderItemService.updateById(orderItem);
        return Result.ok();
    }

}
